<template>
  <div id="homeai" class="homeai">
	  <group class="todayActivityGroup">
		  <div style="margin-top: 10px; margin-bottom: 10px">
			  <span class="blockTitle">智能助理</span>
		  </div>
	  </group>
    <group title="明日待办" class="groupai">
	    <cell v-if="tomorrowActItems.length == 0" title="没有安排任何事项，好的规划有助于提高工作效率。"></cell>
	    <cell v-else class="cellHomeAct"
	          v-for="item in tomorrowActItems"
	          :title="item.time"
	          value-align="left"
	          @click.native="jumpTo(item.activity_id)">
		    <span style="float: left; padding: 5px; background-color: #ff5a00; color: white">{{item.activity_type}}</span>
		    <span style="float: left; padding: 5px;">{{item.name}}</span>
		    <!--<span style="background-color: rgb(67, 171, 227); color: white">{{item.activity_type}}</span>
		    {{item.name}}-->
	    </cell>
    </group>
	  <group title="待跟踪客户" class="groupai">
		  <cell v-if="customerNotActiveItems.length == 0" title="没有待跟踪客户，非常好！"></cell>
		  <cell class="subgroupaiCell" v-for="item in customerNotActiveItems" @click.native="jumpToCustomer(item.id)" :title=item.name>
			  <img slot="icon" width="50" style="display:block;margin-right:5px;" src="../../../../assets/profile/default_header.svg">
		  </cell>
	  </group>
  </div>
</template>

<script>
	import dateutils from '../../../../utils/date'
	import NetWorking from '@/utils/networking'
  import {Group, Cell} from 'vux'
  export default {
    name: "homeai",
    components:{
      Group,
      Cell
    },
    data() {
      return {
	      tomorrowActItems: [],
	      customerNotActiveItems: []
      }
    },
	  created: function () {
		  let _this = this
		  let user = this.$store.state.user.userModel.sysUser
		  let date = dateutils.getNextDayDate(new Date())
		  NetWorking.doGet(
			  'ai/sales/getSalesAIModel',
			  null,
			  {
				  params: {
					  date: date,
					  role: 'consultant',
					  username: user.username,
					  actType: 'S_LOV_SALES'
				  }
			  }
		  ).then(
			  response => {
				  let rs = response.data
				  if(rs.error_code == 0){
					  _this.tomorrowActItems = rs.tomorrowAct
					  _this.customerNotActiveItems = rs.customerNotActive
				  }else{
					  alert(rs.error_message)
				  }
			  }
		  )
	  },
	  methods: {
		  jumpTo: function (id) {
			  //组件间传递参数
			  this.$router.push({ name: "activityDetails", params: { id: id }})
		  },
		  jumpToCustomer: function (id) {
			  this.$router.push({ name: 'customerDetails', params: { id: id }})
		  }
	  }
  }
</script>

<style>
  .homeai{
    border: solid;
    border-color: #f7f7fa;
    margin-bottom: 10px;
	  background: white;
  }

  .groupaiCell{
	  padding: 0px 15px!important;
  }

  .groupai > .weui-cells__title{
	  font-weight: bold;
	  font-size: 14px;
	  color: gray;
  }

  .groupai > .weui-cells > .weui-cell {
	  padding: 0px 15px!important;
  }

	.todayActivityGroup > .weui-cells {
		margin-top: 0em !important;
	}
</style>
